<view class="">
	
</view>

<script>
import { addUserDuration } from '@/services/login.js';
export default {
	data() {
		return {
			globalData: {
				statusBarHeight: 0,
				toBar: 44
			},
			timer: null
		};
	},
	onLaunch: function () {
		this.getHight();
		this.$set(this.globalData, 'toBar', 44);
		wx.setStorageSync('globalData', this.globalData);
	},

	methods: {
		async addUserDurationData(time) {
			const res = await addUserDuration(time);
		},
		addZero(num) {
			return num < 10 ? '0' + num : num; // 如果数值不足两位则添加前导零
		},
		getTime() {
			var currentTime = new Date(); // 创建一个表示当前时间的Date对象

			// 将年、月、日、小时、分钟和秒转换成两位数字并连接起来形成所需的格式
			var formattedTime =
				currentTime.getFullYear() +
				'-' +
				(currentTime.getMonth() + 1) +
				'-' +
				currentTime.getDate() +
				' ' +
				this.addZero(currentTime.getHours()) +
				':' +
				this.addZero(currentTime.getMinutes()) +
				':' +
				this.addZero(currentTime.getSeconds());
			console.log(formattedTime, 'ujy'); // 输出结果：2023-05-26 14:30:45（根据当前时间而定）;

			this.addUserDurationData({ timeStamp: formattedTime });
		},
		getHight() {
			//获取系统信息， 状态栏高度为 sysInfo['statusBarHeight'];
			let _that = this;
			// 获取手机系统信息
			wx.getSystemInfo({
				success: (res) => {
					//导航高度
					// this.globalData.navHeight = res.statusBarHeight + 44;
					_that.globalData.statusBarHeight = res.statusBarHeight;
				},
				fail(err) {
					console.log(err);
				}
			});
		}
	},
	mounted() {
			console.log('mounted');
		this.timer = setInterval(() => {
			console.log('执行了');
			//需要定时执行的代码
			this.getTime();
		}, 60 * 1000);
	},
	onShow: function () {},
	onHide: function () {
		if (this.timer) {
			clearInterval(this.timer);
			this.timer = null;
		}
	}
};
</script>

<style lang="scss">
/*每个页面公共css */

ul {
	padding: 0;
}

li {
	list-style: none;
}

.uni-tabbar {
	height: 80px;
}

::-webkit-scrollbar {
	display: none;
	width: 0;
	height: 0;
	color: transparent;
}
</style>
